package com.IntelligenceInsight.Myth.mapper;

import com.IntelligenceInsight.Myth.model.MLJob;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import org.apache.ibatis.annotations.Param;

import java.util.List;

@Mapper
@Repository
public interface MLJobMapper {
    @Select("SELECT * FROM mljob WHERE owner=#{owner} ORDER BY id DESC")
    List<MLJob> MLJobListByOwner(@Param("owner") String owner);

    @Select("SELECT * FROM mljob ORDER BY timePublish DESC LIMIT #{page},#{limit}")
    List<MLJob> MLJobListAll(@Param("page") int page, @Param("limit") int limit);

    @Select("SELECT COUNT(*) FROM mljob")
    int MLJobListAllCount();

    @Select("SELECT * FROM mljob WHERE uuid=#{uuid}")
    MLJob MLJobByUuid(@Param("uuid") String uuid);

    @Select("SELECT * FROM mljob WHERE name=#{name}")
    MLJob MLJobByName(@Param("name") String name);

    @Select("SELECT * FROM mljob WHERE algorithm=#{algorithm} ORDER BY id DESC")
    List<MLJob> MLJobByAlgorithm(@Param("algorithm")  String algorithm);

    @Insert("INSERT INTO mljob(uuid, algorithm, model, owner, parameters) VALUES(#{uuid}, #{name}, #{model}, #{owner}, #{parameters}, #{result})")
    int MLJobAdd(@Param("uuid") String uuid, @Param("name") String name, @Param("algorithm") String algorithm, @Param("owner") String owner, @Param("parameters") String parameters, @Param("result") String result);

    @Update("UPDATE mljob set state=#{uuid}, result=#{state} WHERE uuid=#{uuid}")
    int MLJobStateChange(@Param("uuid") String uuid, @Param("state")  String state, @Param("result")  String result);

    @Delete("DELETE FROM mljob WHERE uuid=#{uuid}")
    int MLJobDelete(@Param("uuid") String uuid);

}
